package com.school.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mysql.fabric.xmlrpc.base.Data;
import com.school.entity.HljtClass;
import com.school.entity.web.Translate;
import com.school.service.HljtClassService;
import com.school.service.impl.HljtTranslateServiceImpl;
import com.school.util.Message;
import com.school.util.RepUtil;

@Controller
public class HljtTranslateController {
	
	@Autowired
	private HljtClassService hljtClassService;
	@Autowired
	private HljtTranslateServiceImpl hljtTranslateServiceImpl;
	
	/**
	 * 考勤查询接口
	 * @param classid
	 * @param pageSize
	 * @param pageIndex
	 * @param rep
	 * @return
	 */
	@RequestMapping("/selecttranslateall")
	@ResponseBody
	public Message selectTranslateall(Integer classid,Integer pageSize,Integer  pageIndex,HttpServletResponse rep){
		RepUtil.repPake(rep);
		Message Message=new Message();
		Map<String, Object> data =new HashMap<>();
		if(null !=classid) {
			if(classid>-1) {
				pageIndex=(pageIndex-1)*pageSize;
				List<HljtClass> Class=hljtClassService.pageFindClassList(classid,null,null,null);
				List<Translate> translate=hljtTranslateServiceImpl.findTranslateall(classid, pageSize, pageIndex);
				List<Translate> translateall=hljtTranslateServiceImpl.findTranslateall(classid, null, null);
				
				data.put("Totle", translateall.size());
				data.put("data", translate);
				data.put("class", Class);
				data.put("success", true);
			}else {
				classid=null;
				pageIndex=(pageIndex-1)*pageSize;
				List<HljtClass> Class=hljtClassService.pageFindClassList(classid,null,null,null);
				List<Translate> translate=hljtTranslateServiceImpl.findTranslateall(classid, pageSize, pageIndex);
				List<Translate> translateall=hljtTranslateServiceImpl.findTranslateall(classid, null, null);
				
				data.put("Totle", translateall.size());
				data.put("data", translate);
				data.put("class", Class);
				data.put("success", true);
			}
		}else {
			data.put("success", false);
		}
		Message.setData(data);
		return Message;
	}
	/**
	 * 
	 * @param classid
	 * @param pageSize
	 * @param pageIndex
	 * @param rep
	 * @return
	 */
	@RequestMapping("/selecttranslate")
	@ResponseBody
	public Message selectTranslate(Integer classid,String studentname,Integer pageSize,Integer  pageIndex,HttpServletResponse rep){
		RepUtil.repPake(rep);
		Message Message=new Message();
		Map<String, Object> data =new HashMap<>();
		pageIndex=(pageIndex-1)*pageSize;
		if(null !=classid &&null !=studentname&&studentname.length()>0) {
			List<HljtClass> Class=hljtClassService.pageFindClassList(classid,null,null,null);
			List<Translate> translate=hljtTranslateServiceImpl.findTranslate(classid, studentname, null, null);
			List<Translate> translatepage=hljtTranslateServiceImpl.findTranslate(classid, studentname, pageSize, pageIndex);
			data.put("data", translatepage);
			data.put("Totle", translate.size());
			data.put("class", Class);
			data.put("success", true);
		}else if(null !=classid && classid>0){
			List<HljtClass> Class=hljtClassService.pageFindClassList(classid,null,null,null);
			List<Translate> translate=hljtTranslateServiceImpl.findTranslate(classid, null, null, null);
			List<Translate> translatepage=hljtTranslateServiceImpl.findTranslate(classid, null, pageSize, pageIndex);
			data.put("data", translatepage);
			data.put("Totle", translate.size());
			data.put("class", Class);
			data.put("success", true);
		}else if(null !=studentname && studentname.length()>0){
			List<HljtClass> Class=hljtClassService.pageFindClassList(null,null,null,null);
			List<Translate> translate=hljtTranslateServiceImpl.findTranslate(null, studentname, null, null);
			List<Translate> translatepage=hljtTranslateServiceImpl.findTranslate(null, studentname, pageSize, pageIndex);
			data.put("data", translatepage);
			data.put("Totle", translate.size());
			data.put("class", Class);
			data.put("success", true);
		}else {
			List<HljtClass> Class=hljtClassService.pageFindClassList(null,null,null,null);
			List<Translate> translate=hljtTranslateServiceImpl.findTranslate(null, null, null, null);
			List<Translate> translatepage=hljtTranslateServiceImpl.findTranslate(null, null, pageSize, pageIndex);
			data.put("data", translatepage);
			data.put("Totle", translate.size());
			data.put("class", Class);
			data.put("success", true);
		}
		Message.setData(data);
		return Message;
		}
	
	
}
